<?php
/**
 * Gets value of configuration parameter
 * @param string $k parameter name
 * @return mixed parameter value
 */
function _cfg($k)
{
    static $cfg = array();
if (!$cfg){
        // get common settings
		require_once('config/systems.php');
        require_once('config/server.php');
        require_once('config/common.php');
        

        // get modules settings
        $mods = glob($cfg['path'] . '_inc/mod/*', GLOB_ONLYDIR);
        foreach ($mods as $mod)
          	if (file_exists($mod.'/config/config.php')){
        		include $mod.'/config/config.php';
        	}
        
    }    
    if ($cfg[$k])
        return $cfg[$k];
    if (strpos($k,".") !== false){
        $t =explode(".", $k);
        if (isset($cfg[$t[0]]) && is_array($cfg[$t[0]]) && isset($cfg[$t[0]][$t[1]]))
            return $cfg[$t[0]][$t[1]];
    }
}

/**
 * Prints human readable info about $param
 *
 * @param mixed $param info to display
 * @param bool $isDie
 */
function _d($param, $isDie=false)
{
    echo '<hr><pre><xmp>';
    if (is_bool($param))
    	$param = $param? "True" : "False";
    print_r($param);
    echo '</xmp></pre><hr>';
    if ($isDie)
        die();
}


function grubber($url){
	$data = file_get_contents($url);
	$data = iconv("windows-1251", "UTF-8", $data);
	$data = str_replace(array("\r\n", "\r", "\n",'\t'), '', $data); 
	$data =  preg_replace('/\s{2,}/',' ',$data);
	return $data;
}


function _pager($pager){
	if($pager['current'] > 1){
		$pager['prevUrl'] = $pager['current'] - 1;
	}else{
		$pager['prevUrl'] = 0;
	}		
	if($pager['current'] < $pager['totalPages']){
		$pager['nextUrl'] = $pager['current'] + 1;
	}else{
		$pager['nextUrl'] = 0;
	}
	return $pager;
}

